/************************************************************
Copyright (C) Xiong,Hui at www.51embed.com
FileName: init.c
Author: Xiong,Hui huixiong73@gmail.com
Date:08/3/13
Description: uart process
Version: 1.0
Function List: 
    1. uart_rece();
History: 
    1. Huixiong 08/4/19 build this moudle
***********************************************************/
#include <intrins.h>
#include <string.h>
#include "at89x52.H"
#include "uart.h"

/*************************************************************
*  Function:uart_rece()
*  Description:	a simple example that show the data received by uart being proessed 
*  Calls:
*  Called by:main()
*  Input:
*  Output:
*  Return:
*  Others:
*  History:
       1. Huixiong 08/4/19 created
*************************************************************/
void uart_rece(void)
{	
	if(uartreceflag == TRUE){    //uart has received a data frame ended by \r\n
	   uartreceflag = FALSE; 
	   while(echoflag || uartsendflag ){  //wait until there is no data waiting for sending
	       ;
	   }

	   if(uartreceptr >=3){
			 strcpy(&uartsendbuf,&wrong);
			 uartsendptr=sizeof(wrong);
	   }else{
	       switch(uartrecebuf[0]){
		       case '0':
			       strcpy(&uartsendbuf,&right0);
				   uartsendptr=sizeof(right0);
				   break;
			   case '1':
			       strcpy(&uartsendbuf,&right1);
				   uartsendptr=sizeof(right1);
				   break;
			   case '2':
			       strcpy(&uartsendbuf,&right2);
				   uartsendptr=sizeof(right2);
				   break;
			   case '3':
			       strcpy(&uartsendbuf,&right3);
				   uartsendptr=sizeof(right3);
				   break;
			   case '4':
			       strcpy(&uartsendbuf,&right4);
				   uartsendptr=sizeof(right4);
				   break;
			   case '5':
			       strcpy(&uartsendbuf,&right5);
				   uartsendptr=sizeof(right5);
				   break;
			   case '6':
			       strcpy(&uartsendbuf,&right6);
				   uartsendptr=sizeof(right6);
				   break;
			   case '7':
			       strcpy(&uartsendbuf,&right7);
				   uartsendptr=sizeof(right7);
				   break;
			   default:
			   	    strcpy(&uartsendbuf,&right);
				   uartsendptr=sizeof(right);
			       break;
		   }
	   }
	   uartreceptr = 0x0;
	   uartsendtempptr = 0x0;
	   uartsendflag = TRUE;
	   TI = 1;						//intiates the sending
	}
}
